<%@page import="com.egame.manage.biz.server.gc.TerminalServiceImpl"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="cn.egame.interfaces.gc.TerminalRecognitionInfo" %>
<%@ page import="cn.egame.interfaces.gc.TerminalInfo" %>
<%@ page import="java.util.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href="<%=request.getContextPath()%>/css/main.css"  />
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/common.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		$("#upBtn1").click(function() {
			$("#searchTable tbody").remove();
			var popOS = document.getElementById("popOS").value;
			var popScreenPX = document.getElementById("popScreenPX").value;
			var popManufacturer = document.getElementById("popManufacturer").value;
			var popModelName = document.getElementById("popModelName").value;
			$.ajax({			
				url : "<%=request.getContextPath() + "/tv/terminal/identify.do" %>",
				type : 'post',
				data:{
					'popOS':popOS,
					'popScreenPX':popScreenPX,
					'popManufacturer':popManufacturer,
					'popModelName':popModelName
				},
				success : function(msg) {
					$("#searchTable").append("<tbody></tbody>");
					var i=0;
					if(msg != null){
						$.each(msg,function(key,values){  
							++i;
							var trString = '<tr class="search_tr">';
							var endString = '</tr>';
						    var tdString = '<td align="left" width="15%" class="d_search"><input type="radio" name="checkbox_model" class="t_search" value="'+
						    		key+'"><span>'+values+'</span></td>';
						    if(i%4==1){
						    	$("#searchTable tbody").append(trString).append(tdString);
						    }else if(i%4==0){
						    	$("#searchTable tbody").append(tdString).append(endString);
						    }else{
						    	$("#searchTable tbody").append(tdString);
						    }
						});  
					}
				}
			});
		});
		
		$("#queding").click(function() {
			var model = $('input[name="checkbox_model"]:checked').val();
			var sp_text = $('input[name="checkbox_model"]:checked + span').text();
			$("#terId").attr("value",model);
			$("#ter_ua").text(sp_text);
			$("#shortua").attr("value",sp_text);
			closeDialog('fileInfo');
		});
		
		$("#cancel").click(function() {
			closeDialog('fileInfo');
		});
	});

	function formSubmit(){
		var td = $("#form1").find("td[name='notnone']");
		var isSubmit = true;
		for(var i = 0; i<td.length; i++){
			if($(td[i]).find("input[type='text']").val() == ""){
				$(td[i]).find("span").remove();
				$(td[i]).append("<span class='page_tip'>*必填</span>");
				isSubmit = false;
				return;
			}else{
				$(td[i]).find("span").remove();
			}
		}
		if(isSubmit){
			document.getElementById("form1").submit();
		}else{
			return;
		}
	}	
	
	function showDetail() {
		setDialog('fileInfo');
	}
</script>
<title>编辑机型识别信息</title>
</head>
<body>
<% 
	List<TerminalInfo> terminalInfos = new ArrayList<TerminalInfo>();
	if(request.getAttribute("list")!=null){
		terminalInfos = (List<TerminalInfo>)request.getAttribute("list");
	}
	
	List<String> terminalNames = new ArrayList<String>();
	if(request.getAttribute("terminalNames")!=null){
		terminalNames = (List<String>)request.getAttribute("terminalNames");
	}
	
	List<String> terminalOs = new ArrayList<String>();
	if(request.getAttribute("terminalOs")!=null){
		terminalOs = (List<String>)request.getAttribute("terminalOs");
	}
	
	List<String> terminalScreens = new ArrayList<String>();
	if(request.getAttribute("terminalScreens")!=null){
		terminalScreens = (List<String>)request.getAttribute("terminalScreens");
	}
%>
<% String urlString = request.getContextPath() + "/tv/terminal/update/recognition.do"; %>
<div class="matter_box">
	<div class="mt10 pt10 clearfix">
<form action="<%=urlString %>" method="post" id="form1">
<% if(request.getAttribute("bean")!=null){
			TerminalRecognitionInfo bean = (TerminalRecognitionInfo) request.getAttribute("bean");
			TerminalInfo terminal = TerminalServiceImpl.getInstance().getTerminalInfo(0, 0L, bean.getTerminalId());
	 %>
	<input type="hidden" id="terId" name="terId" value="<%=bean.getTerminalId() %>">
	<input type="hidden" id="ter_ua" name="ter_ua" value="<%=terminal.getShortUA() %>">
	<table class="table2">	
		<tr>		
			<td align=right>API Level</td>
			<td align=left>
				<input type=hidden name=apiCode value=<%=bean.getApiCode() %>>
				<%=bean.getApiCode() %>
			</td>
		</tr>
		<tr>		
			<td align=right>Model</td>
			<td align=left>
				<input type=hidden name=uaCode value="<%=bean.getUaCode()%>" >
				<%=bean.getUaCode()%>
			</td>
		</tr>
		<tr>		
			<td align=right>分辨率</td>
			<td align=left name="notnone">
				<input type=hidden name=screenPx value=<%=bean.getScreenPx() %>>
				<%=bean.getScreenPx() %>
			</td>
		</tr>
		<tr>		
			<td align=right>机型</td>
			<td align=left name="notnone">	
				<input type="text" maxlength="30" name="shortua" id="shortua" value=<%=terminal.getShortUA() %>>
			 	<a id="chooseModel" name="chooseModel" href="javascript:showDetail()" class="btn2">选择机型</a>			
			</td>
		</tr>
		<tr>		
			<td align=right>是否典型机型</td>
			<td align=left name="notnone">
				<input type="radio" name=isTypical value="1" <% if(bean.getIsTypical()==1){ %> checked="checked" <%} %>>是
				<input type="radio" name=isTypical value="0" <% if(bean.getIsTypical()==0){ %> checked="checked" <%} %>>否
		</tr>
		<tr>		
			<td align=right>备注</td>
			<td align=left><input type=text name=remark value=<%=bean.getRemark() %>></td>
		</tr>
		<tr><td colspan=2><input type="button" value="提交" class="btn3" onclick="formSubmit()"></td></tr>
	<% } %>
	</table>
</form>
</div>
</div>
<div class="dialog_table editor_group" id="fileInfo" style="width:400px">
	<form action="<%=request.getContextPath() + "/tv/terminal/identify.do" %>" method="post" id="modelForm" style="height:300px; overflow: auto;">
		<table>
			<tr>
				    <td>操作系统：</td>
	                      <td>
	                      	<select name="popOS" id="popOS" style="width: 155px;">
	                      		<option value="">请选择</option>
	                      	<%
								for(String os:terminalOs){
									%>
										<option value="<%=os%>"><%=os%></option>
									<%
								}
							%>
	                      	</select>
	                      </td>
	        </tr>
	        <tr>
	                      <td>分辨率：</td>
	                      <td>
	                      	<select name="popScreenPX" id="popScreenPX" style="width: 155px;">
	                      		<option value="">请选择</option>
		                      	<%
									for(String screen:terminalScreens){
										%>
											<option value="<%=screen%>"><%=screen%></option>
										<%
									}
								%>
		                      	
	                      	</select>
	                      </td>
	         </tr>
	        <tr>             
	                      <td>厂商：</td>
	                      <td>
	                      	<select name="popManufacturer" id="popManufacturer" style="width: 155px;">
								<option value="">请选择</option>
								<%
									for(String name:terminalNames){
										%>
											<option value="<%=name%>"><%=name%></option>
										<%
									}
								%>
								
							</select>
	                      </td>
	            </tr>
	        	<tr>
	                      <td>识别机型：</td>
						  <td><input type="text" id="popModelName" name="popModelName" maxlength="30" style="width: 120px;"></td>
	                      <td style="width: 150px;">
	                      	<input type="button" id="upBtn1" class="btn3" style="cursor:hand;width:74px; " name="uploadBtn" value="查询">
	                      </td>
				</tr>
				<tr>
					<table id="searchTable" style="height: 150px;overflow: auto;">
						<tbody>
						</tbody>
					</table>
				</tr>
				<tr>
						<td colspan="8" align="center">
	                      	<input type="button" id="queding" class="btn3" style="cursor:hand;width:74px; " name="uploadBtn" value="确定">
	                      	<input type="button" id="cancel" class="btn3" style="cursor:hand;width:74px;" name="uploadBtn" value="取消">
	                      </td>
				</tr>
		</table>
	</form>
</div>
</body>
</html>